﻿using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UT_AMS.DataAccess.BO;
using AMS.DataAccess.Sql;

namespace UT_AMS.DataAccess
{
    /// <summary>
    /// Summary description for UT_SqlInsert
    /// </summary>
    [TestClass]
    public class UT_SqlDelete_Compact
    {
        public UT_SqlDelete_Compact()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestBasic()
        {
            var sql = new SqlDelete("RealUserTable");
            sql.AddCondition(new SqlCondition("AID", 1));

            string ssql = sql.ToString();
            Assert.IsTrue(ssql.IndexOf("\r\n") >= 0);


            sql = new SqlDelete("RealUserTable");
            sql.CompactMode = true;
            sql.AddCondition(new SqlCondition("AID", 1));

            ssql = sql.ToString();
            Assert.IsTrue(ssql.IndexOf("\r\n") < 0);


            sql = new SqlDelete("RealUserTable", true);
            sql.AddCondition(new SqlCondition("AID", 1));

            ssql = sql.ToString();
            Assert.IsTrue(ssql.IndexOf("\r\n") < 0);


            sql = new SqlDelete("RealUserTable");
            sql.AddCondition(new SqlCondition("AID", 1));

            sql.CompactMode = true;
            ssql = sql.ToString();
            Assert.IsTrue(ssql.IndexOf("\r\n") >= 0);
        }

        [TestMethod]
        public void Test_多条件()
        {
            var sql = new SqlDelete("RealUserTable", true);
            sql.AddCondition(new SqlCondition("AID", 1));
            sql.AddCondition(new SqlCondition("Name", "小明"));
            sql.AddCondition("Name = '小小明'");

            string ssql = sql.ToString();
            Assert.IsTrue(ssql.IndexOf("\r\n") < 0);
            Assert.IsTrue(ssql.IndexOf(" Name =") >= 0);
            Assert.IsTrue(ssql.IndexOf("  Name =") < 0);
            Assert.IsTrue(ssql.IndexOf(" AID =") >= 0);
            Assert.IsTrue(ssql.IndexOf("  AID =") < 0);

        }
    }
}
